package cn.mrcode.fd.blog.buutil.restfull;

import org.springframework.http.HttpStatus;

/**
 * restfull 返回json结果工具类
 * @author zhuqiang
 * @version V1.0
 * @date 2016/7/14 0014 16:00
 */
public class RestFulResultUtil {
    private static RestFulResult succ = new RestFulResult();
    private static RestFulResult fail = new RestFulResult();
    static {
        fail.setCode("1");
    }
    public static RestFulResult success(){
        return succ.clone();
    }
    public static RestFulResult success(Object data){
        RestFulResult result = succ.clone();
        result.setData(data);
        return result;
    }

    public static RestFulResult success(String code,String msg,Object data){
        RestFulResult result = succ.clone();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    public static RestFulResult success(HttpStatus httpStatus,Object data){
        RestFulResult result = succ.clone();
        result.setData(data);
        result.setStatus(httpStatus.value());
        return result;
    }

    public static RestFulResult fail(){
        return fail.clone();
    }
    public static RestFulResult fail(Object data){
        RestFulResult result = fail.clone();
        result.setData(data);
        return result;
    }

    public static RestFulResult fail(String code,String msg,Object data){
        RestFulResult result = fail.clone();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
    public static RestFulResult fail(HttpStatus httpStatus,Object data){
        RestFulResult result = fail.clone();
        result.setData(data);
        result.setStatus(httpStatus.value());
        return result;
    }
}
